/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package daw.bean;

import java.io.Serializable;
import java.util.Iterator;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;


@Entity
@Table(name = "area", catalog = "defensor", schema = "")
@NamedQueries({@NamedQuery(name = "Area.findAll", query = "SELECT a FROM Area a"),
@NamedQuery(name = "Area.findByIdArea", query = "SELECT a FROM Area a WHERE a.idArea = :idArea"),
@NamedQuery(name = "Area.findByNombre", query = "SELECT a FROM Area a WHERE a.nombre = :nombre"),
@NamedQuery(name = "Area.findByReferencia", query = "SELECT a FROM Area a WHERE a.referencia = :referencia")})
public class Area implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "idArea")
    private Integer idArea;
    @Basic(optional = false)
    @Column(name = "nombre")
    private String nombre;
    @Basic(optional = false)
    @Column(name = "referencia")
    private String referencia;
    @JoinColumn(name = "idCiudad", referencedColumnName = "idCiudad")
    @ManyToOne(optional = false)
    private Ciudad idCiudad;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "idArea")
    private List<Denuncia> denunciaCollection;

    public Area() {
    }

    public Area(Integer idArea) {
        this.idArea = idArea;
    }

    public Area(Integer idArea, String nombre, String referencia) {
        this.idArea = idArea;
        this.nombre = nombre;
        this.referencia = referencia;
    }

    public Integer getIdArea() {
        return idArea;
    }

    public void setIdArea(Integer idArea) {
        this.idArea = idArea;
    }

    public String getNombre() {
        return nombre;
    }

    public void setNombre(String nombre) {
        this.nombre = nombre;
    }

    public String getReferencia() {
        return referencia;
    }

    public void setReferencia(String referencia) {
        this.referencia = referencia;
    }

    public Ciudad getIdCiudad() {
        return idCiudad;
    }

    public void setIdCiudad(Ciudad idCiudad) {
        this.idCiudad = idCiudad;
    }

    public List<Denuncia> getDenunciaCollection() {
        return denunciaCollection;
    }

    public void setDenunciaCollection(List<Denuncia> denunciaCollection) {
        this.denunciaCollection = denunciaCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idArea != null ? idArea.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Area)) {
            return false;
        }
        Area other = (Area) object;
        if ((this.idArea == null && other.idArea != null) || (this.idArea != null && !this.idArea.equals(other.idArea))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "daw.bean.Area[idArea=" + idArea + "]";
    }

    public String toXML(){
        String xml = "<area>";
        xml+="<idarea>"+getIdArea()+"</idarea>";
        xml+="<nombre>"+getNombre()+"</nombre>";
        xml+="<referencia>"+getReferencia()+"</referencia>";
        xml+="<idciudad>"+getIdCiudad().getIdCiudad()+"</idciudad>";
        xml+="</area>";
        return xml;
    }

    public static String AreaCollectionToXML(List<Area> areas){
        String xml="<areas>";
        Iterator i = areas.iterator();
        while(i.hasNext()){
            Area c = (Area)i.next();
            xml+=c.toXML();
        }
        xml+="</areas>";
        return xml;
    }

}
